import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SPublicNotice } from "../../../../Message/Public/SPublicNotice";
import { ChatMessageWorking } from "../../view/chat/chatViewData/ChatMessageWorking";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { EShowArea } from "../../../../Message/Public/EShowArea";
import { MsgManager } from "../../manager/MsgManager";
import { SystemSetter } from "../../view/system/SystemSetter";
import { EChatType } from "../../../../Message/Public/EChatType";
import { GameController } from "../../mvc/GameController";
import { ChatType } from "../../view/chat/chatViewData/ChatType";
import { ChatArea } from "../../view/chat/ChatArea";
import { ChatStyle } from "../../view/chat/chatPanel/ChatStyle";
import { MsgType } from "../../manager/MsgType";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ECopyType } from "../../../../Message/Public/ECopyType";
import { Cache } from "../../cache/Cache";
import { ColorConfig } from "../../resource/ColorConfig";
import { CellDataType } from "../../view/chat/chatViewData/CellDataType";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
type int = number;
//class NoticeMsgCommand
    
    export  class NoticeMsgCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=false;
            var loc1=arg1.messageBase as SPublicNotice;
            loc1.content = ChatMessageWorking.getNoticeContent(loc1);
            NetDispatcher.dispatchCmd(ServerCommand.NoticeMsg, loc1);
            if (loc1.area & EShowArea._EShowAreaMiddle) 
            {
                if (loc3 = this.getHtml(loc1)) 
                {
                    MsgManager.showRollRadioMsg(loc3);
                }
            }
            if (loc1.area & EShowArea._EShowAreaMiddleTop) 
            {
                if (!SystemSetter.currentSetter.hideSysBroadcast) 
                {
                    if (loc3 = this.getHtml(loc1)) 
                    {
                        MsgManager.addBroadCast(loc3);
                    }
                }
            }
            if (loc1.area & EShowArea._EShowAreaChat) 
            {
                if (loc1.type == EChatType._EChatTypeGuild) 
                {
                    NetDispatcher.dispatchCmd(ServerCommand.GuildNoticeUpdate, loc1);
                }
                if (loc1.type == EChatType._EChatTypeSystem) 
                {
                    loc5 = loc1.content;
                    GameController.chat.addBackStageMsg(loc5, loc1.publicMiniplayers);
                }
                if (loc1.type == EChatType._EChatTypeRumor) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.Legent);
                }
                if (loc1.type == EChatType._EChatTypeBattleFiled) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.Battlefield);
                }
                if (loc1.type == EChatType._EChatTypeGuildWar) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.GuildWar);
                }
                if (loc1.type == EChatType._EChatTypeArena) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.Arena);
                }
                if (loc1.type == EChatType._EChatTypeMarket) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.Market);
                }
                if (loc1.type == EChatType._EChatTypeCrossStair) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.CrossStair);
                }
                if (loc1.type == EChatType._EChatTypePlant) 
                {
                    GameController.chat.addTypeRumorMsg(loc1.content, loc1.publicMiniplayers, ChatType.Plant);
                }
                if (loc1.type == EChatType._EChatTypeCopy) 
                {
                    GameController.chat.addCopyMsg(loc1.content, loc1.publicMiniplayers);
                }
                if (loc1.type == EChatType._EChatTypeCrossCopy) 
                {
                    loc6 = loc1.code > 0;
                    GameController.chat.addCrossCopyMsg(loc6, loc1.content, loc1.publicMiniplayers);
                }
                if (loc1.type == EChatType._EChatTypeVCampOne || loc1.type == EChatType._EChatTypeVCampTwo || loc1.type == EChatType._EChatTypeVCampThree) 
                {
                    loc2 = this.getShowAreaByCamp();
                    if (loc1.type == loc2) 
                    {
                        GameController.chat.addTipMsg(loc1.content, ChatType.State, ChatArea.Country, 2, loc1.publicMiniplayers, ChatStyle.getTitleColor(ChatType.State));
                    }
                }
                if (loc1.type == EChatType._EChatTypeForce) 
                {
                    loc4 = ChatType.Force;
                    GameController.chat.addTipMsg(loc1.content, loc4, ChatArea.Force, 2, loc1.publicMiniplayers, ChatStyle.getTitleColor(ChatType.System));
                }
                if (loc1.type == EChatType._EChatTypeSpace) 
                {
                    loc4 = ChatType.Scene;
                    if (ChatMessageWorking.chatShowAreaData.indexOf(ChatMessageWorking.crossObj) > -1) 
                    {
                        loc4 = ChatType.CrossServer;
                    }
                    GameController.chat.addTipMsg(loc1.content, loc4, ChatArea.Scene, 2, loc1.publicMiniplayers, ChatStyle.getTitleColor(ChatType.System));
                }
                if (loc1.type == EChatType._EChatTypeWorld) 
                {
                    GameController.chat.addTipMsg(loc1.content, ChatType.World, ChatArea.World, 2, loc1.publicMiniplayers, ChatStyle.getTitleColor(ChatType.World));
                }
            }
            if (loc1.area & EShowArea._EShowArenaFightInfo) 
            {
                if (loc1.type == EChatType._EChatTypeFightInfo) 
                {
                    if (!loc3) 
                    {
                        loc3 = this.getHtml(loc1);
                    }
                    MsgManager.addTipText(loc3, MsgType.FightMsg);
                }
            }
            if (loc1.area & EShowArea._EShowAreaExplorer) 
            {
                if (loc1.type == EChatType._EChatTypeRumor) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.TreasureExplorerRumorAdd, loc1));
                }
            }
            if (loc1.area & EShowArea._EShowAreaRightDown) 
            {
                if (loc3 = this.getHtml(loc1, EShowArea._EShowAreaRightDown)) 
                {
                    MsgManager.showRollTipsMsg(loc3);
                }
            }
            if (loc1.area & EShowArea._EShowAreaMiddleDown) 
            {
                if (loc3 = this.getHtml(loc1)) 
                {
                    MsgManager.showTaskTarget(loc3);
                }
            }
            if (loc1.area & EShowArea._EShowAreaMiddleDownEx) 
            {
                if (_cache.copy.isInCopyType(ECopyType._ECopyGuildStruggle) || _cache.copy.isInCopyType(ECopyType._ECopyGuildDefense)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildCopyShowNoticeMsg, this.getHtml(loc1)));
                }
            }
            return;
        }

        /* internal  */getShowAreaByCamp(): int
        {
            var loc1=EChatType._EChatTypeVCampOne;
            var loc2=Cache.instance.role.entityInfo.camp;
            switch (loc2) 
            {
                case 1:
                {
                    loc1 = EChatType._EChatTypeVCampOne;
                    break;
                }
                case 2:
                {
                    loc1 = EChatType._EChatTypeVCampTwo;
                    break;
                }
                case 3:
                {
                    loc1 = EChatType._EChatTypeVCampThree;
                    break;
                }
            }
            return loc1;
        }

        /* internal  */getHtml(arg1: SPublicNotice, arg2: int=-1): string
        {
            var loc1=0;
            var loc6=null;
            if (arg1.type == EChatType._EChatTypeVCampOne || arg1.type == EChatType._EChatTypeVCampTwo || arg1.type == EChatType._EChatTypeVCampThree) 
            {
                loc1 = this.getShowAreaByCamp();
                if (arg1.type != loc1) 
                {
                    return "";
                }
            }
            var loc2=16777215;
            var loc3;
            if (loc3 = ColorConfig.instance.getChatColor("Rumor")) 
            {
                loc2 = loc3.intColor;
            }
            var loc4=ChatMessageWorking.getCellDatasFilterHtml(arg1.content, loc2, arg1.publicMiniplayers);
            var loc5="";
            var loc7=0;
            while (loc7 < loc4.length) 
            {
                if (!(loc4[loc7].type == CellDataType.RumorTran || loc4[loc7].type == CellDataType.RumorCopy)) 
                {
                    loc6 = HTMLUtil.addColor(loc4[loc7].text, "#" + loc4[loc7].elementFormat.color.toString(16));
                    loc5 = loc5 + loc6;
                }
                ++loc7;
            }
            return loc5;
        }
    }
